package com.tian.view.custom

import android.graphics.Color
import android.graphics.Paint
import android.os.Bundle
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.RoundedCornerTreatment
import com.google.android.material.shape.ShapeAppearanceModel
import com.tian.util.view.DisplayUtil
import com.tian.view.databinding.ActivityCardViewTestBinding

/**
 * @author tiansongtao
 * @date 2023/1/4 18:13
 */
class CardViewActivity : AppCompatActivity() {


    private lateinit var b: ActivityCardViewTestBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        b = ActivityCardViewTestBinding.inflate(layoutInflater)
        setContentView(b.root)
        val shapeModel = ShapeAppearanceModel.builder()
            .setAllCorners(RoundedCornerTreatment())
            .setAllCornerSizes(DisplayUtil.dpToPx(20f))
            .build()
        val backgroundDrawable = MaterialShapeDrawable(shapeModel).apply {
            setTint(Color.WHITE)
            paintStyle = Paint.Style.FILL
//            bounds = Rect(DisplayUtil.dpToPx(1F).toInt(), DisplayUtil.dpToPx(10F).toInt(), DisplayUtil.dpToPx(10F)
//                .toInt(), DisplayUtil.dpToPx(10F).toInt())
            //绘制阴影
            shadowCompatibilityMode = MaterialShapeDrawable.SHADOW_COMPAT_MODE_ALWAYS
            initializeElevationOverlay(this@CardViewActivity)
            setShadowColor(Color.parseColor("#1A6888B0"))
            elevation = DisplayUtil.dpToPx(5F)
        }
        (b.llShape.parent as ViewGroup).clipChildren = false
        b.llShape.background = backgroundDrawable
        //        (textView08.parent as ViewGroup).clipChildren = false

    }
}